#pragma once

#include "IXGifMgr.h"
#include "XBaseObjImpl.h"
#include <map>
#include <vector>

typedef std::vector<XIMAGE> GifFrames;
typedef std::vector<long>   GifDelayValues;

class CXGifMgrImpl : public CXBaseObjImpl<IXGifMgr>
{
    typedef CXBaseObjImpl<IXGifMgr> superclass;
    DEF_SKIN_CLASS_SINGLE_INTF(CXGifMgrImpl,
        superclass,
        gs_strGuidXSkin,
        IXGifMgr,
        eIntf_Singleton);
public:
    CXGifMgrImpl();
    virtual ~CXGifMgrImpl();

public:
    // IXGifMgr
    virtual XGIF    STDMETHODCALLTYPE   LoadGif(IN LPCTSTR szXNC);
    virtual HRESULT STDMETHODCALLTYPE   ReleaseGif(IN XGIF xGif);

    virtual HRESULT STDMETHODCALLTYPE   GetGifSize(IN XGIF xGif, OUT SIZE* pSizeGif);

    virtual DWORD   STDMETHODCALLTYPE   GetFrameCount(IN XGIF xGif);
    virtual HRESULT STDMETHODCALLTYPE   GetFrames(IN XGIF xGif, OUT XIMAGE* pArrFrames, IN DWORD dwMaxCount);

    virtual DWORD   STDMETHODCALLTYPE   GetDelayValueCount(IN XGIF xGif);
    virtual HRESULT STDMETHODCALLTYPE   GetDelayValues(IN XGIF xGif, OUT DWORD* pArrValues, IN DWORD dwMaxCount);

public:
    // IBaseObj
    virtual void    STDMETHODCALLTYPE   OnFinalRelease();

protected:
    void    ReleaseData();

protected:
    struct GifImageInfo
    {
        XString         strXNC;
        int             nRef;
        SIZE            sizeGif;
        GifFrames       vctFrames;
        GifDelayValues  vctDelayValues;
    };
    typedef std::map<XGIF, GifImageInfo> GifImageInfoContainer;
    GifImageInfoContainer   m_GifImageInfo;
};


